package ch.exm.storm.test.domain.impl;

import java.util.Set;

import ch.exm.storm.test.domain.Customer;
import ch.exm.storm.test.domain.Order;
import ch.exm.storm.test.domain.OrderedItem;

public class OrderImpl extends AbstractDomainObject implements Order {

	private String code;
	
	private Set<OrderedItem> orderedItems;
	
	private Customer customer;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Set<OrderedItem> getOrderedItems() {
		return orderedItems;
	}

	public void setOrderedItems(Set<OrderedItem> orderedItems) {
		this.orderedItems = orderedItems;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public double getTotal() {
		double total = 0;
		for (OrderedItem orderedItem : orderedItems) total += orderedItem.getValue();
		return total;
	}
	
	@Override
	public String toString() {
		return "Order[" + getId() + "] is " + getCode() + " with total = " + getTotal();
	}
}
